<?php
/**
 * wap 2.0 用户中心－地址编辑
 */


$filter = empty($_REQUEST['filter']) ? 'add' : trim($_REQUEST['filter']);

$address_id = empty($_REQUEST['address_id']) ? 0 : $_REQUEST['address_id'];

// 新增地址
if ($filter == 'add')
{
	$province_list = $mem->getCache('sexmall_provinces', true);
	if (!is_array($province_list))
	{
		$province_list 	= $mInterface->getShopArea();

		$mem->addCache('sexmall_provinces', $province_list, 0, true);
	}

	$smarty->assign('province', $province_list);

}
// 修改地址
else if ($filter == 'update')
{
	// 取得用户收货地址列表
	$address = get_one_address($mInterface, $user_token, $address_id);

	// 取得省列表
	$province_list = $mem->getCache('sexmall_provinces', true);
	if (!is_array($province_list))
	{
		$province_list 	= $mInterface->getShopArea();
		$mem->addCache('sexmall_provinces', $province_list, 0, true);
	}
	// 取得市列表
	$city_list = $mem->getCache('sexmall_citys_'.$address['province']['regionId'], true);
	if (empty($city_list) || !is_array($city_list))
	{
		$city_list = $mInterface->getShopArea($address['province']['regionId']);
		$mem->addCache('sexmall_citys_'.$address['province']['regionId'], $city_list, 0, true);
	}
	// 取得区列表
	$district_list = $mem->getCache('sexmall_districts_'.$address['city']['regionId'], true);
	if (empty($district_list) || !is_array($district_list))
	{
		$district_list 	= $mInterface->getShopArea(0, $address['city']['regionId']);
		$mem->addCache('sexmall_district_'.$address['city']['regionId'], $district_list, 0, true);
	}

	/* OMNITURE 统计  */
	$pageName = '用户中心-收货地址编辑';
	include 'omniture/other.php';

	$smarty->assign('consignee', 	$address);

	$smarty->assign('province', 	$province_list);
	$smarty->assign('city', 		$city_list);
	$smarty->assign('district', 	$district_list);


}
// 删除地址
else if ($filter == 'del')
{
	$address_id = empty($_REQUEST['address_id']) ? 0 : $_REQUEST['address_id'];
	$mInterface->delUserAddress($user_token, $address_id);

	$back_act = wap_getcookie("WAP[back_act]");
	if (empty($back_act)){
		$back_act = "user-order-list.html";
	}
	wap_header("Location: " . $back_act);
	exit;
}

$smarty->assign('step', $step);
$smarty->assign('filter', $filter);

$smarty->display('user_address_edit.dwt');